% crossover rate based on probability
function [crossedPopulation] =  hw8Crossover(population, numPairs)

crossedPopulation = population;
[popSize, popElem] = size(population);
% we need to add the new crossover at the end
k = popSize+1;
pair = 0;
% run for number of new child paris required
while pair <numPairs
    % find random parents
    popToCrossA = int16((popSize - 1)*rand(1)+1);
    popToCrossB = int16((popSize - 1)*rand(1)+1);
    % find crossover parents
    crossoverPoint = int16((popElem - 1)*rand(1)+1);

    crossedChA = population(popToCrossA,:);
    crossedChB = population(popToCrossB,:);
    crossAPos = crossoverPoint+1;
    i = crossAPos;
    % cross children
    while i <=popElem
        crossedChA(1,i) = population(popToCrossB, i);
        i = i + 1;
    end
    for i = 1:crossoverPoint
        crossedChB(1,i) = population(popToCrossA,i);
    end
    crossedPopulation(k,:) = crossedChA(1,:);
    crossedPopulation(k+1,:) = crossedChB(1,:);
    k=k+2;
    pair = pair + 1;
end
